import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      meta: { title: "图书列表" },
      component: () => import("@/views/Home.vue"),
    },
    {
      path: '/addBook',
      meta: { title: "新增图书" },
      component: () => import("@/views/AddBook.vue"),
    },
    {
      path: '/updateBook/:id',
      meta: { title: "修改图书" },
      component: () => import("@/views/UpdateBook.vue"),
    },
  ],
})

// 全局守卫
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
